package com.situ.skymall.admin.api.controller;

import com.situ.model.CnRegionInfo;
import com.situ.skymall.admin.api.service.CnRegionInfoFeignService;
import com.situ.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地区信息 Controller
 */
@RestController
@RequestMapping("/api/v1/region")
public class CnRegionInfoController {

    private final CnRegionInfoFeignService cnRegionInfoFeignService;

    @Autowired
    public CnRegionInfoController(CnRegionInfoFeignService cnRegionInfoFeignService) {
        this.cnRegionInfoFeignService = cnRegionInfoFeignService;
    }

    /**
     * 获取所有省份数据
     */
    @GetMapping("/provinces")
    public JsonResult<List<CnRegionInfo>> getProvinces() {
        return cnRegionInfoFeignService.getProvinces();
    }

    /**
     * 获取指定省份下的城市数据
     */
    @GetMapping("/cities/{provinceCode}")
    public JsonResult<List<CnRegionInfo>> getCities(@PathVariable String provinceCode) {
        return cnRegionInfoFeignService.getCities(provinceCode);
    }

    /**
     * 获取指定城市下的区县数据
     */
    @GetMapping("/districts/{cityCode}")
    public JsonResult<List<CnRegionInfo>> getDistricts(@PathVariable String cityCode) {
        return cnRegionInfoFeignService.getDistricts(cityCode);
    }

    /**
     * 输入id只返回直接子节点
     */
    @GetMapping("/tree/{parentId}")
    public JsonResult<List<CnRegionInfo>> getRegionTree(@PathVariable Integer parentId) {
        return cnRegionInfoFeignService.getRegionTree(parentId);
    }

    /**
     * 获取完整地址树
     */
    @GetMapping("/full-tree/{code}")
    public JsonResult<CnRegionInfo> getFullAddressTree(@PathVariable String code) {
        return cnRegionInfoFeignService.getFullAddressTree(code);
    }

    /**
     * 根据地区代码获取完整地址信息
     */
    @GetMapping("/full-address/{code}")
    public JsonResult<String> getFullAddress(@PathVariable String code) {
        return cnRegionInfoFeignService.getFullAddress(code);
    }

    /**
     * 根据名称搜索地区
     */
    @GetMapping("/search")
    public JsonResult<List<CnRegionInfo>> searchRegion(@RequestParam String name) {
        return cnRegionInfoFeignService.searchRegion(name);
    }
}
